package org.rfs.ipodencoder;
import java.util.Arrays;
import java.util.List;

import com.trolltech.qt.core.QFileInfo;
import com.trolltech.qt.core.QMimeData;
import com.trolltech.qt.core.QUrl;
import com.trolltech.qt.core.Qt;
import com.trolltech.qt.gui.*;

public class QFileListWidget extends QListWidget{
	public Signal0 dropped = new Signal0();
	
    public QFileListWidget(QWidget parent){
        super(parent);
    }
    
    @Override
    protected boolean dropMimeData(int index, QMimeData data, Qt.DropAction action) {
    	List<QUrl> urlList = data.urls(); // retrieve list of urls
    	QFileInfo fileInfo;
    	
        //TODO: extend this to support only allowed file types (avi, mkv, mpeg, ...)
    	//TODO: do not allow multiple entries
    	
    	for (QUrl url : urlList) {
    		fileInfo = new QFileInfo(url.toLocalFile());
    		if (fileInfo.isFile())
    			addItem(fileInfo.absoluteFilePath());
    	}
    	dropped.emit();
    	return true;
    }
    
    @Override
    protected List<String> mimeTypes() {
		return Arrays.asList("text/uri-list");	
    }    
}